package constant

import (
	"github.com/Unknwon/goconfig"
	"runtime"
)

const (
	defaultHeaderPath    = "src/test2020/stats/resource/header.ini"
	defaultHeaderSection = "Header"
	defaultConfigPath    = "src/test2020/stats/resource/config.ini"
	defaultConfigSection = "Config"
	fileDir              = "FileDir"
	baseUrl              = "BaseUrl"
	indexUrl             = "IndexUrl"

	requestConfigName = "request.json"
)

var (
	FileDir       = ""
	HeaderPath    = defaultHeaderPath
	HeaderSection = defaultHeaderSection

	RequestConfigName = requestConfigName

	BaseUrl  = ""
	IndexUrl = ""

	NumCPU = 0

	Headers = map[string]string{}
)

func InitConfig() {
	// reader config.ini
	config, _ := goconfig.LoadConfigFile(defaultConfigPath)
	FileDir, _ = config.GetValue(defaultConfigSection, fileDir)
	BaseUrl, _ = config.GetValue(defaultConfigSection, baseUrl)
	IndexUrl, _ = config.GetValue(defaultConfigSection, indexUrl)

	// NumCPU
	NumCPU = runtime.NumCPU()
}

func DestroyConfig() {
	FileDir = ""
	BaseUrl = ""
	IndexUrl = ""
}

func SetHeaders(headers map[string]string) {
	Headers = headers
}
